//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "tools\fn_getVehicleTurrets.sqf"
#include <tmf_constants.h>
#include <tmf_macros.h>

TRACE_1("Start",_this);
TMFPROFILERSTART;

private ["_turrets","_entry", "_turretIndex","_subEntry","_hasGunner"];
DEFAULT_PARAM(_entry,0,[]);

_turrets = [];
if (IS_CONFIG(_entry)) then {
	_turretIndex = 0;
	for "_i" from 0 to ((count _entry) - 1) do {
		_subEntry = _entry select _i;
		if (isClass _subEntry) then {
			_hasGunner = [_subEntry, "hasGunner"] call FFUNC(getConfigEntry);
			if (!(isNil "_hasGunner")) then {
				if (_hasGunner == 1) then {
					_turrets set [count _turrets, _turretIndex];
					if (isClass (_subEntry >> "Turrets")) then {
						_turrets set [count _turrets, [_subEntry >> "Turrets"] call FFUNC(getVehicleTurrets)];
					} else {
						_turrets set [count _turrets, []];
					};
				};
			};
			_turretIndex = _turretIndex + 1;
		};
	};
} else {
	ERROR("Invalid Parameters");
};
TRACE_1("End",_turrets);
TMFPROFILERSTOP;
_turrets